﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using DBUtility;//请先添加引用
namespace DBEmr.DAL
{
	/// <summary>
	/// 数据访问类EMPLOYEE。
	/// </summary>
	public class EMPLOYEE
	{
		public EMPLOYEE()
		{
			DbHelperOra.connectionString=PubConstant.GetConfig("DBEMR");
		}
		#region  成员方法


		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from EMPLOYEE");
			strSql.Append(" where ID='"+ID+"' ");
			return DbHelperOra.Exists(strSql.ToString());
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void Add(DBEmr.Model.EMPLOYEE model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into EMPLOYEE(");
			strSql.Append("ID,EM_NAME,EM_SEX,EM_WORKADDRESS,EM_SEEADOCTOR_NUM,EM_BIRTHDATA,EM_EDUCATIONALBACKGROUND,EM_SCHOOLGRADUATING,EM_STATE,EM_TELEPHONE,EM_FAMILYADDRESS,EM_MOBILEPHONE,EM_PARSONTOCONTACT,EM_PTN_PHONE,EM_PYM,EM_NATION,EM_NATIVEPLACE,EM_ID_CARD,EM_ZIP_CODE,EM_MEDICINE_ID,EM_WORK_TIME,EM_TYPE,EM_POSITION,EM_EXPERT,EM_KIND,EM_OFFICEHOLDER");
			strSql.Append(")");
			strSql.Append(" values (");
			strSql.Append("'"+model.ID+"',");
			strSql.Append("'"+model.EM_NAME+"',");
			strSql.Append("'"+model.EM_SEX+"',");
			strSql.Append("'"+model.EM_WORKADDRESS+"',");
			strSql.Append("'"+model.EM_SEEADOCTOR_NUM+"',");
            strSql.Append("to_date('" + model.EM_BIRTHDATA.ToString() + "','YYYY-MM-DD HH24:MI:SS'),");
			strSql.Append("'"+model.EM_EDUCATIONALBACKGROUND+"',");
			strSql.Append("'"+model.EM_SCHOOLGRADUATING+"',");
			strSql.Append("'"+model.EM_STATE+"',");
			strSql.Append("'"+model.EM_TELEPHONE+"',");
			strSql.Append("'"+model.EM_FAMILYADDRESS+"',");
			strSql.Append("'"+model.EM_MOBILEPHONE+"',");
			strSql.Append("'"+model.EM_PARSONTOCONTACT+"',");
			strSql.Append("'"+model.EM_PTN_PHONE+"',");
			strSql.Append("'"+model.EM_PYM+"',");
			strSql.Append("'"+model.EM_NATION+"',");
			strSql.Append("'"+model.EM_NATIVEPLACE+"',");
			strSql.Append("'"+model.EM_ID_CARD+"',");
			strSql.Append("'"+model.EM_ZIP_CODE+"',");
			strSql.Append("'"+model.EM_MEDICINE_ID+"',");
            strSql.Append("to_date('" + model.EM_WORK_TIME.ToString() + "','YYYY-MM-DD HH24:MI:SS'),");
			strSql.Append("'"+model.EM_TYPE+"',");
			strSql.Append("'"+model.EM_POSITION+"',");
			strSql.Append("'"+model.EM_EXPERT+"',");
			strSql.Append("'"+model.EM_KIND+"',");
			strSql.Append("'"+model.EM_OFFICEHOLDER+"'");
			strSql.Append(")");
			DbHelperOra.ExecuteSql(strSql.ToString());
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public void Update(DBEmr.Model.EMPLOYEE model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update EMPLOYEE set ");
			strSql.Append("EM_NAME='"+model.EM_NAME+"',");
			strSql.Append("EM_SEX='"+model.EM_SEX+"',");
			strSql.Append("EM_WORKADDRESS='"+model.EM_WORKADDRESS+"',");
			strSql.Append("EM_SEEADOCTOR_NUM='"+model.EM_SEEADOCTOR_NUM+"',");
            strSql.Append("EM_BIRTHDATA=" + "to_date('" + model.EM_BIRTHDATA.ToString() + "','YYYY-MM-DD HH24:MI:SS'),");
			strSql.Append("EM_EDUCATIONALBACKGROUND='"+model.EM_EDUCATIONALBACKGROUND+"',");
			strSql.Append("EM_SCHOOLGRADUATING='"+model.EM_SCHOOLGRADUATING+"',");
			strSql.Append("EM_STATE='"+model.EM_STATE+"',");
			strSql.Append("EM_TELEPHONE='"+model.EM_TELEPHONE+"',");
			strSql.Append("EM_FAMILYADDRESS='"+model.EM_FAMILYADDRESS+"',");
			strSql.Append("EM_MOBILEPHONE='"+model.EM_MOBILEPHONE+"',");
			strSql.Append("EM_PARSONTOCONTACT='"+model.EM_PARSONTOCONTACT+"',");
			strSql.Append("EM_PTN_PHONE='"+model.EM_PTN_PHONE+"',");
			strSql.Append("EM_PYM='"+model.EM_PYM+"',");
			strSql.Append("EM_NATION='"+model.EM_NATION+"',");
			strSql.Append("EM_NATIVEPLACE='"+model.EM_NATIVEPLACE+"',");
			strSql.Append("EM_ID_CARD='"+model.EM_ID_CARD+"',");
			strSql.Append("EM_ZIP_CODE='"+model.EM_ZIP_CODE+"',");
			strSql.Append("EM_MEDICINE_ID='"+model.EM_MEDICINE_ID+"',");
            strSql.Append("EM_WORK_TIME=" + "to_date('" + model.EM_WORK_TIME.ToString() + "','YYYY-MM-DD HH24:MI:SS'),");
			strSql.Append("EM_TYPE='"+model.EM_TYPE+"',");
			strSql.Append("EM_POSITION='"+model.EM_POSITION+"',");
			strSql.Append("EM_EXPERT='"+model.EM_EXPERT+"',");
			strSql.Append("EM_KIND='"+model.EM_KIND+"',");
			strSql.Append("EM_OFFICEHOLDER='"+model.EM_OFFICEHOLDER+"'");
			strSql.Append(" where ID='"+ model.ID+"' ");
			DbHelperOra.ExecuteSql(strSql.ToString());
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public void Delete(string ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete EMPLOYEE ");
			strSql.Append(" where ID='"+ID+"' " );
			DbHelperOra.ExecuteSql(strSql.ToString());
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public DBEmr.Model.EMPLOYEE GetModel(string ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,EM_NAME,EM_SEX,EM_WORKADDRESS,EM_SEEADOCTOR_NUM,EM_BIRTHDATA,EM_EDUCATIONALBACKGROUND,EM_SCHOOLGRADUATING,EM_STATE,EM_TELEPHONE,EM_FAMILYADDRESS,EM_MOBILEPHONE,EM_PARSONTOCONTACT,EM_PTN_PHONE,EM_PYM,EM_NATION,EM_NATIVEPLACE,EM_ID_CARD,EM_ZIP_CODE,EM_MEDICINE_ID,EM_WORK_TIME,EM_TYPE,EM_POSITION,EM_EXPERT,EM_KIND,EM_OFFICEHOLDER ");
			strSql.Append(" from EMPLOYEE ");
			strSql.Append(" where ID='"+ID+"' " );
			DBEmr.Model.EMPLOYEE model=new DBEmr.Model.EMPLOYEE();
			DataSet ds=DbHelperOra.Query(strSql.ToString());
			if(ds.Tables[0].Rows.Count>0)
			{
				model.ID=ds.Tables[0].Rows[0]["ID"].ToString();
				model.EM_NAME=ds.Tables[0].Rows[0]["EM_NAME"].ToString();
				model.EM_SEX=ds.Tables[0].Rows[0]["EM_SEX"].ToString();
				model.EM_WORKADDRESS=ds.Tables[0].Rows[0]["EM_WORKADDRESS"].ToString();
				model.EM_SEEADOCTOR_NUM=ds.Tables[0].Rows[0]["EM_SEEADOCTOR_NUM"].ToString();
				if(ds.Tables[0].Rows[0]["EM_BIRTHDATA"].ToString()!="")
				{
					model.EM_BIRTHDATA=DateTime.Parse(ds.Tables[0].Rows[0]["EM_BIRTHDATA"].ToString());
				}
				model.EM_EDUCATIONALBACKGROUND=ds.Tables[0].Rows[0]["EM_EDUCATIONALBACKGROUND"].ToString();
				model.EM_SCHOOLGRADUATING=ds.Tables[0].Rows[0]["EM_SCHOOLGRADUATING"].ToString();
				model.EM_STATE=ds.Tables[0].Rows[0]["EM_STATE"].ToString();
				model.EM_TELEPHONE=ds.Tables[0].Rows[0]["EM_TELEPHONE"].ToString();
				model.EM_FAMILYADDRESS=ds.Tables[0].Rows[0]["EM_FAMILYADDRESS"].ToString();
				model.EM_MOBILEPHONE=ds.Tables[0].Rows[0]["EM_MOBILEPHONE"].ToString();
				model.EM_PARSONTOCONTACT=ds.Tables[0].Rows[0]["EM_PARSONTOCONTACT"].ToString();
				model.EM_PTN_PHONE=ds.Tables[0].Rows[0]["EM_PTN_PHONE"].ToString();
				model.EM_PYM=ds.Tables[0].Rows[0]["EM_PYM"].ToString();
				model.EM_NATION=ds.Tables[0].Rows[0]["EM_NATION"].ToString();
				model.EM_NATIVEPLACE=ds.Tables[0].Rows[0]["EM_NATIVEPLACE"].ToString();
				model.EM_ID_CARD=ds.Tables[0].Rows[0]["EM_ID_CARD"].ToString();
				model.EM_ZIP_CODE=ds.Tables[0].Rows[0]["EM_ZIP_CODE"].ToString();
				model.EM_MEDICINE_ID=ds.Tables[0].Rows[0]["EM_MEDICINE_ID"].ToString();
				if(ds.Tables[0].Rows[0]["EM_WORK_TIME"].ToString()!="")
				{
					model.EM_WORK_TIME=DateTime.Parse(ds.Tables[0].Rows[0]["EM_WORK_TIME"].ToString());
				}
				model.EM_TYPE=ds.Tables[0].Rows[0]["EM_TYPE"].ToString();
				model.EM_POSITION=ds.Tables[0].Rows[0]["EM_POSITION"].ToString();
				model.EM_EXPERT=ds.Tables[0].Rows[0]["EM_EXPERT"].ToString();
				model.EM_KIND=ds.Tables[0].Rows[0]["EM_KIND"].ToString();
				model.EM_OFFICEHOLDER=ds.Tables[0].Rows[0]["EM_OFFICEHOLDER"].ToString();
				return model;
			}
			else
			{
				return null;
			}
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,EM_NAME,EM_SEX,EM_WORKADDRESS,EM_SEEADOCTOR_NUM,EM_BIRTHDATA,EM_EDUCATIONALBACKGROUND,EM_SCHOOLGRADUATING,EM_STATE,EM_TELEPHONE,EM_FAMILYADDRESS,EM_MOBILEPHONE,EM_PARSONTOCONTACT,EM_PTN_PHONE,EM_PYM,EM_NATION,EM_NATIVEPLACE,EM_ID_CARD,EM_ZIP_CODE,EM_MEDICINE_ID,EM_WORK_TIME,EM_TYPE,EM_POSITION,EM_EXPERT,EM_KIND,EM_OFFICEHOLDER ");
			strSql.Append(" FROM EMPLOYEE ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperOra.Query(strSql.ToString());
		}

		/*
		*/

		#endregion  成员方法
	}
}

